﻿using SimpleWifi;
using static JMBox.Config.R;

namespace JMBox.Utils
{
    public class WiFiTool
    {

        private static Wifi wifia = new Wifi();
        public static bool ConnectWiFiNet()
        {
            try
            {
                var g = wifia.GetAccessPoints();
                foreach (var item in g)
                {
                    if (item.Name == GlobalConfig.WifiName)
                    {
                        AuthRequest ar = new AuthRequest(item);
                        ar.Password = GlobalConfig.WifiPwd;
                        item.Connect(ar);

                        if (!item.Connect(ar))
                        {
                            //MessageBox.Show("网络连接失败");
                        }
                        else
                        {
                            //MessageBox.Show("网络连接成功");
                        }
                    }
                }
                return true;
            }
            catch { return false; }
        }

        public static bool ShutWiFiNet()
        {
            try
            {
                wifia.Disconnect();
                return true;
            }
            catch { return false; }
        }
    }
}
